package com.kotlin.lib.coroutines

import kotlinx.coroutines.*
import kotlin.coroutines.EmptyCoroutineContext

fun main() = runBlocking<Unit> {
    val handler = CoroutineExceptionHandler { _, throwable ->
        println("error: " + throwable.localizedMessage)
    }
    val coroutineScope = CoroutineScope(handler + EmptyCoroutineContext)

    val job1 = coroutineScope.launch {
        delay(1000)
        println("!!!")
    }

    val job2 = coroutineScope.launch {
        delay(100)
        throw IllegalAccessException("i'm a error")
        println("job2")
    }
    job1.join()
    try {
        job2.join()
    } catch (e: Exception) {
    }
}